package com.itheima.Vue.web.manager.web;

import com.itheima.Vue.web.manager.pojo.PageBean;
import com.itheima.Vue.web.manager.service.ContactService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

@WebServlet("/PageQueryServlet")
public class PageQueryServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost( request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收请求
        String pageStr = request.getParameter("page");
        String countStr = request.getParameter("count");
        String keyword = request.getParameter("keyword");
        String minAge = request.getParameter("minAge");
        String maxAge = request.getParameter("maxAge");
        //搜索条件
        HashMap<String,String> conditionMap = new HashMap<>();
        conditionMap.put("keyword",keyword);
        conditionMap.put("minAge",minAge);
        conditionMap.put("maxAge",maxAge);
        //2.业务处理
        ContactService service = new ContactService();
        PageBean bean = service.pageQuery(pageStr,countStr,conditionMap);

        //3.请求转发
        request.setAttribute("bean",bean);
        request.setAttribute("map",conditionMap);
        request.getRequestDispatcher("list.jsp").forward(request,response);

    }
}